﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;

using Coder.IdeOne;
using Windows.Storage;
using System.IO;

namespace Coder.Framework
{
    /// <summary>
    /// Represents a serializable profile for the user.
    /// </summary>
    public class Profile
    {
        static readonly string profileLocation = "profile.xml";
        public List<Project> ProjectList { get; set; }
        public string UserName { get; set; }
        public int Points { get; set; }
        public List<Challenge> ChallengesComplete { get; set; }

        public Credentials UserCredentials { get; set; }

        public Profile() { }

        /// <summary>
        /// Saves the profile in the Roaming Folder of the Windows Profile so it can be accessed globally through all accounts.
        /// </summary>
        public async Task SaveProfile()
        {
            await FileAccess<Profile>.SaveFile(this, profileLocation);
        }

        /// <summary>
        /// Loads the profile from the Roaming Folder, if it exists.
        /// </summary>
        public static async Task<Profile> LoadProfile()
        {
            try
            {
                return await FileAccess<Profile>.LoadFile(profileLocation);
            }
            catch (Exception) { }

            return new Profile() { ChallengesComplete = new List<Challenge>() };
        }
    }
}
